/*
 * UserProductsServlet.java
 * 作用：处理用户"我的商品"页面的请求，获取当前用户发布的所有商品。
 */
package com.campustradingwall.controller.user;

import com.campustradingwall.dao.ProductDao;
import com.campustradingwall.model.Product;
import com.campustradingwall.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/user/products")
public class UserProductsServlet extends HttpServlet {
    private ProductDao productDao = new ProductDao();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getSession().getAttribute("user");
        List<Product> products = productDao.getProductsByUserId(user.getId());

        request.setAttribute("products", products);
        request.getRequestDispatcher("/user/products.jsp").forward(request, response);
    }
} 